import 'package:flutter/material.dart';

import 'package:tencent_cloud_chat_uikit/theme/color.dart';
import 'package:tencent_chat_i18n_tool/tencent_chat_i18n_tool.dart';
import 'package:tencent_cloud_chat_uikit/ui/utils/screen_utils.dart';

import 'package:provider/provider.dart';
import 'package:tencent_cloud_chat_demo/config.dart';
import 'package:tencent_cloud_chat_demo/src/provider/theme.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';

class Qrcode extends StatefulWidget {
  final String account;
  const Qrcode({Key? key, required this.account}) : super(key: key);

  @override
  State<StatefulWidget> createState() => QrcodeState();
}

class QrcodeState extends State<Qrcode> {
  final GlobalKey _globalKey = GlobalKey();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(
    BuildContext context,
  ) {
    final theme = Provider.of<DefaultThemeData>(context).theme;
    final isWideScreen =
        TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop;
    final account = 'https://chat.vsl.cn/G10.html?c=${widget.account}';
    debugPrint("account: $account");
    return Scaffold(
        appBar: isWideScreen
            ? null
            : AppBar(
                iconTheme: const IconThemeData(
                  color: Colors.white,
                ),
                shadowColor: theme.weakDividerColor,
                elevation: 1,
                title: Text(
                  TIM_t("二维码名片"),
                  style: const TextStyle(
                    fontSize: IMDemoConfig.appBarTitleFontSize,
                    color: Colors.white, // 设置字体颜色为白色
                  ),
                ),
                flexibleSpace: Container(
                  decoration: BoxDecoration(
                    gradient: LinearGradient(colors: [
                      theme.lightPrimaryColor ?? CommonColor.lightPrimaryColor,
                      theme.primaryColor ?? CommonColor.primaryColor
                    ]),
                  ),
                ),
              ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              RepaintBoundary(
                key: _globalKey,
                child: PrettyQr(
                  data: account,
                  errorCorrectLevel: QrErrorCorrectLevel.H,
                  size: 200, // 设置二维码大小为 200
                  image: const AssetImage(
                    'assets/logo.png',
                  ),
                  // 设置二维码中间的图片
                ),
              ),
              const SizedBox(height: 20),
              Center(
                child: Text(
                  TIM_t("扫一扫上面的二维码图案，加我为朋友吧！"),
                  style: TextStyle(
                    fontSize: 12,
                    color: theme.black,
                  ),
                ),
              ),
            ],
          ),
        ));
  }
}
